/* Copyright (C) 2011 clueless <clueless.mmopeon@gmail.com>
 *
 * This file is part of MMO Peon.
 *
 * MMO Peon is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MMO Peon is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MMO Peon.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "movement.h"
#include "../log.h"

MovementState::MovementState(PlayerMovement *movement, Waypoints *wps) : BaseState(20)
{
    this->movement = movement;
    this->wps = wps;
}

bool MovementState::Ready()
{
    return (memBase != 0 && memBase->player != 0);
}

void MovementState::Enter()
{
    LogWrite(LOG_NORMAL, "Entering movement state, finding nearest waypoint");
    movement->Move(wps->Nearest(memBase->player->coords));
}

void MovementState::Update()
{
    if (!movement->IsBusy())
    {
        LogWrite(LOG_NORMAL, "We're not busy, moving to next wp");
        movement->Move(wps->Next());
    }

    movement->Update();
}

void MovementState::Exit()
{
    movement->Stop();
    LogWrite(LOG_NORMAL, "Exiting movement state!");
}
